import Taro from '@tarojs/taro';
import * as sdk from './fetch';

/**
 * 查询游戏信息接口
 * @param params
 * @returns
 */
async function getGameIpConfigInfo(params = {}): Promise<any> {
  let result = await sdk.post<any>(`/game-base-config/getByGameType`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询赠送游戏次数
 */
async function getGameTimesReceiveDaily(params = {}): Promise<any> {
  let result = await sdk.post<any>(`customergamecount/daily-gift`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询游戏可用次数
 */
async function getGameTimesConfigInfo(params = {}): Promise<any> {
  console.log('syntheticCardController getGameTimesConfigInfo params', params);
  let result = await sdk.post<any>(`customergamecount/find-current-user-available-game-count`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询抽抽卡用户已获得称号记录
 * @param params
 * @returns
 */
async function getAppellationItems(params = {}): Promise<any> {
  let result = await sdk.post<any>(`drawcardgameusertitlerecord/list`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询卡库内容
 * @param params
 * @returns
 */
async function getCardItems(params = {}): Promise<any> {
  let result = await sdk.post<any>(`drawcardgameusercard/card-list-ip`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询ip列表
 * @param params
 * @returns
 */
async function getIpItems(params = {}): Promise<any> {
  console.log('synthecticCardController getIpItems params', params);
  let result = await sdk.post<any>(`drawcardgameprizeconfig/list`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 是否是新人保障
 * @param params
 * @returns
 */
async function userIsNewComer(params = {}): Promise<any> {
  console.log('syntheticCardController userIsNewComer params', params);
  let result = await sdk.post<any>(`game-base-config/isNewcomer`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 合成卡片
 * @param params
 * @returns
 */
async function cardSynthetic(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`drawcardgameusercard/fusion`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }

  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 抽奖
 * @param params
 */
async function gameLottery(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`game-base-config/lottery`, {
      ...params,
    });
  } catch (e) {
    result = e;
    if (e.code == 'K-000001') {
      Taro.showToast({
        title: '操作失败',
        icon: 'none',
      });
    }
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getGameIpConfigInfo,
  getGameTimesReceiveDaily,
  getGameTimesConfigInfo,
  getAppellationItems,
  getCardItems,
  getIpItems,
  userIsNewComer,
  cardSynthetic,
  gameLottery,
};
